use serde::{Deserialize, Serialize};

use crate::graph::value::Value;

use super::{Input, NodeTrait, Output};

#[derive(Clone, Serialize, Deserialize)]
pub struct IncludeCustomDataNode {
    pub name: String,
    pub data: Value,
    pub file: String,
    description: String,
    inputs: Vec<Input>,
    outputs: Vec<Output>,
}

impl IncludeCustomDataNode {
    pub fn new(file:String, name: String, data: Value) -> Self {
        Self {
            description: format!("外部自定义数据节点，引用自文件: {}", file),
            file,
            name,
            data: data.clone(),
            inputs: vec![],
            outputs: vec![Output {
                name: "Data".to_string(),
                description: Some("外部自定义数据".to_string()),
                value: data,
            }],
        }
    }
}

impl NodeTrait for IncludeCustomDataNode {
    fn name(&self) ->  &str {
        &self.name
    }

    fn ty(&self) ->  &str {
        "__INCLUDE_CUSTOM_DATA_NODE__"
    }

    fn description(&self) -> Option<&str> {
        Some(&self.description)
    }

    fn inputs(&self) ->  &[Input] {
        &self.inputs
    }

    fn outputs(&self) ->  &[Output] {
        &self.outputs
    }

    fn has_children(&self) -> bool {
        false
    }

    fn inputs_mut(&mut self) ->  &mut Vec<Input> {
        &mut self.inputs
    }

    fn outputs_mut(&mut self) ->  &mut Vec<Output> {
        &mut self.outputs
    }
}